package com.druid.common.config.secutity;

import com.druid.model.ResponseData;
import com.druid.util.UtilForHttpServletData;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Log4j2
@Component("myAuthenctiationSuccessHandler")
@RequiredArgsConstructor
public class MyAuthenctiationSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {


    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException {

            ResponseData<String> success = ResponseData.SUCCESS("登入成功");
            success.setMessage("登入成功");
            UtilForHttpServletData.responseDataForHttp( response, success );

    }
}
